{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<script type="text/javascript">
    $(document).ready(function() {
        $('#expectedtime').daterangepicker(null, function(start, end, label) {
            console.log(start.toISOString(), end.toISOString(), label);
        });
    });

</script>
<style>
    .file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
    .file-item .info{overflow: hidden;}
    .uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>修改收支信息</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="incomeAdd" id="incomeAdd" method="post" action="{:url('incomeEdit')}">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">收支分类：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="type" id="type" onchange="typeChange()">
                                    <option value="1" {if condition="$info.type == 1"}selected{/if}>收入</option>
                                    <option value="2" {if condition="$info.type == 2"}selected{/if}>支出</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">项目名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="name" value="{$info.name}" >
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group" id="shou" >
                            <label class="col-sm-3 control-label">收入类型：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="income_type" id="income_type">
                                    <option value="0">==请选择==</option>
                                    {volist name="Think.config.income_type" id="group"}
                                    <option value="{$key}"  {if condition="$info.leixing == $key"}selected{/if} >{$group}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="form-group" id="zhi" >
                            <label class="col-sm-3 control-label">支出类型：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="payment_type" id="payment_type">
                                    <option value="0">==请选择==</option>
                                    {volist name="Think.config.payment_type" id="group"}
                                    <option value="{$key}" {if condition="$info.leixing == $key"}selected{/if} >{$group}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>


                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">负责人：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="user_id" id="user_id">
                                    <option value="">==请选择角色==</option>
                                    {if !empty($user)}
                                    {foreach name="user" item="vo"}
                                    <option value="{$vo.id}" {if condition="$info.user_id == $vo.id"}selected{/if} >{$vo.real_name}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">金额：</label>
                            <div class="input-group col-sm-4">
                                <input id="money" type="text" class="form-control" name="money" value="{$info.money}" >
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">预计到款时间：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" name="expectedtime" onclick="laydate()" value="{$info.expectedtime}"  id="expectedtime" class="form-control layer-date" placeholder="2017-10-01"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">简单描述：</label>
                            <div class="input-group col-sm-4">
                                <textarea type="text" rows="5" name="content" id="remark" placeholder="输入该笔款项的简单描述" class="form-control">{$info.content}</textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <input type="hidden" name="id" value="{$info.id}">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>

<script type="text/javascript">

    //提交
    $(function(){
        $('#incomeAdd').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $.trim($('#name').val())){
                layer.msg('请输入项目',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

            var type = $('#type option:selected') .val();//选中的值

            if(type==1){
                if($('#income_type option:selected') .val()==0){
                    layer.msg('请选择收入类型',{icon:2,time:1500,shade: 0.1}, function(index) {
                        layer.close(index);
                    });
                    return false;
                }
            }else if(type==2){
                if($('#payment_type option:selected') .val()==0){
                    layer.msg('请选择支出类型',{icon:2,time:1500,shade: 0.1}, function(index) {
                        layer.close(index);
                    });
                    return false;
                }
            }

            if( '' == $.trim($('#money').val())){
                layer.msg('请输入金额',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

            if($('#user_id option:selected') .val()==0){
                layer.msg('请选择负责人',{icon:2,time:1500,shade: 0.1}, function(index) {
                    layer.close(index);
                });
                return false;
            }

            if( '' == $.trim($('#expectedtime').val())){
                layer.msg('请输入预计到款时间',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }


        }


        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('incomepayment/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;
            }
        }

    });


    function typeChange(){
        var type = $('#type option:selected') .val();//选中的值
        if(type==1){
            document.getElementById('zhi').style.display="none";
        }else if(type==2){
            document.getElementById('shou').style.display="none";
        }
    }



    //IOS开关样式配置
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, {
        color: '#1AB394'
    });
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

    var type = $('#type option:selected') .val();//选中的值
    if(type==1){
        document.getElementById('zhi').style.display="none";
        document.getElementById('shou').style.display="block";
    }else if(type==2){
        document.getElementById('zhi').style.display="block";
        document.getElementById('shou').style.display="none";
    }


</script>
</body>
</html>


